<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>建议管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script>

    layui.use(['table','form'], function(){
        var table = layui.table;//layui中使用html的table
        var $ = layui.$;//layui中使用jQuery
        var form = layui.form;
        var usertab = table.render({//表格渲染
            elem: '#test'
            ,url:'/contact/showAll'
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,cols: [[//列  标题栏
                {field:'zizeng', title: '序号', width:80 , sort: true,templet:'#zizeng',fixed: 'left'}
                ,{field:'conname', title: '建议者姓名', width:90}
                ,{field:'conemail', title: '建议者邮箱'}
                ,{field:'conphone', title: '建议者电话'}
                ,{field:'conhelp', title: '建议',width:300}
                ,{field:'contime', title: '建议时间', width:180}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:80 }
            ]]
            ,page:true
        });
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定要删除吗', function(){
                    $.ajax({
                        url:'/contact/del/'+data.conid,
                        type:'delete',
                        success:function (d){
                            if(d === 1){
                                layer.msg('删除成功',{
                                    icon:1,
                                    time:1000//不配置默认3秒
                                },function(){
                                    //更新表格
                                    usertab.reload({
                                        page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                        ,where: {
                                            conid:null
                                        }
                                    });
                                });
                            }
                        }
                    });

                });
            }
        });
    });
</script>
<script type="text/html" id="zizeng">
    {{d.LAY_TABLE_INDEX+1}}
</script>
</body>
</html>